package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.acticle.domain.Destination;
import cn.wolfcode.luowowo.acticle.domain.DestinationTheme;
import cn.wolfcode.luowowo.acticle.query.DestinationThemeQuery;
import cn.wolfcode.luowowo.acticle.service.IDestinationService;
import cn.wolfcode.luowowo.acticle.service.IDestinationThemeService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class DestinationThemeController {

    @Reference
    private IDestinationThemeService destinationThemeService;
    @Reference
    private IDestinationService destinationService;

    @RequestMapping("/getDestinationTheme")
    public String getDestinationTheme(Model model, Long id){

        List<DestinationTheme> tes = destinationThemeService.getDestinationThemeById(id);
        model.addAttribute("tes",tes);

        return "destination/themeTpl";
    }

    @RequestMapping("/travelFilter")
    public String travelFilter(Model model, @ModelAttribute("qo")DestinationThemeQuery qo){

        //查所有的主题
        model.addAttribute("allyear",destinationThemeService.getDestinationThemeById(1L));
        model.addAttribute("season",destinationThemeService.getDestinationThemeById(2L));
        model.addAttribute("way",destinationThemeService.getDestinationThemeById(3L));
        model.addAttribute("holiday",destinationThemeService.getDestinationThemeById(4L));

        //根据条件查找目的地
        PageInfo pageInfo = destinationService.queryDestByQo(qo);
        model.addAttribute("pageInfo",pageInfo);

        return "destination/destFilter";
    }

    @RequestMapping("/destFilterPage")
    public String destFilterPage(Model model, @ModelAttribute("qo")DestinationThemeQuery qo){

        //根据条件查找目的地
        PageInfo pageInfo = destinationService.queryDestByQo(qo);
        model.addAttribute("pageInfo",pageInfo);

        return "destination/destFilterDetail";
    }

    @RequestMapping("/getDestinationByMonth")
    public String getDestinationByMonth(Model model, @ModelAttribute("qo")DestinationThemeQuery qo){

        //根据条件查找目的地
        List<Destination> list = destinationService.queryDestinationByMonth(qo.getViewMonth());
        model.addAttribute("monthDetail",list);

        return "destination/monthDetail";
    }
}
